3 # Update already-installed software
6 include( "./install-utils.inc" );
7 install_version_checks();
9 if ( ! ( is_readable( "./LocalSettings.php" )
10 && is_readable( "./AdminSettings.php" ) ) ) {
11 print "A copy of your installation's LocalSettings.php\n" .
12 "and AdminSettings.php must exist in this source directory.\n";
17 include_once( "./LocalSettings.php" );
18 include_once( "./AdminSettings.php" );
20 include( "$IP/Version.php" );
22 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
23 print "To use math functions, you must first compile texvc by\n" .
24 "running \"make\" in the math directory.\n";
29 # Copy files into installation directories
33 $wgDBuser = $wgDBadminuser;
34 $wgDBpassword = $wgDBadminpassword;
36 include_once( "{$IP}/Setup.php" );
37 include_once( "./maintenance/InitialiseMessages.inc" );
39 $wgTitle = Title
::newFromText( "Update script" );
42 # Check the database for things that need to be fixed...
44 print "Checking database for necessary updates...\n";
46 $wgDatabase = Database
::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname,
47 1, false, true, false);
48 if ( !$wgDatabase->isOpen() ) {
49 print "Unable to connect to database: " . $wgDatabase->lastError() . "\n";
53 do_revision_updates();
56 do_interwiki_update();
59 do_hitcounter_update();
60 do_recentchanges_update();
73 function do_update_files() {
74 global $IP, $wgStyleSheetDirectory, $wgUploadDirectory, $wgLanguageCode, $wgDebugLogFile;
75 print "Copying files... ";
77 copyfile( ".", "index.php", $IP );
78 copyfile( ".", "redirect.php", $IP );
79 # compatibility with older versions, can be removed in a year or so
80 # (written in Feb 2004)
81 copyfile( ".", "wiki.phtml", $IP );
82 copyfile( ".", "redirect.phtml", $IP );
84 copydirectory( "./includes", $IP );
85 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
87 copyfile( "./images", "wiki.png", $wgUploadDirectory );
88 copyfile( "./images", "button_bold.gif", $wgUploadDirectory );
89 copyfile( "./images", "button_extlink.gif", $wgUploadDirectory );
90 copyfile( "./images", "button_headline.gif", $wgUploadDirectory );
91 copyfile( "./images", "button_hr.gif", $wgUploadDirectory );
92 copyfile( "./images", "button_image.gif", $wgUploadDirectory );
93 copyfile( "./images", "button_italic.gif", $wgUploadDirectory );
94 copyfile( "./images", "button_link.gif", $wgUploadDirectory );
95 copyfile( "./images", "button_math.gif", $wgUploadDirectory );
96 copyfile( "./images", "button_media.gif", $wgUploadDirectory );
97 copyfile( "./images", "button_sig.gif", $wgUploadDirectory );
98 copyfile( "./images", "button_template.gif", $wgUploadDirectory );
100 copyfile( "./languages", "Language.php", $IP );
101 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
103 if( !empty( $wgDebugLogFile ) ) {
104 $fp = fopen( $wgDebugLogFile, "w" );
105 if ( false === $fp ) {
106 print "Could not create log file \"{$wgDebugLogFile}\".\n";
109 $d = date( "Y-m-d H:i:s" );
110 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
115 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
116 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
117 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
120 copyfile( ".", "Version.php", $IP );
125 function do_revision_updates() {
126 global $wgSoftwareRevision;
127 if ( $wgSoftwareRevision < 1001 ) {
132 function update_passwords() {
134 $fname = "Update script: update_passwords()";
135 print "\nIt appears that you need to update the user passwords in your\n" .
136 "database. If you have already done this (if you've run this update\n" .
137 "script once before, for example), doing so again will make all your\n" .
138 "user accounts inaccessible, so be sure you only do this once.\n" .
139 "Update user passwords? (yes/no)";
141 $resp = readconsole();
142 if ( ! ( "Y" == $resp{0} ||
"y" == $resp{0} ) ) { return; }
144 $sql = "SELECT user_id,user_password FROM user";
145 $source = $wgDatabase->query( $sql, $fname );
147 while ( $row = $wgDatabase->fetchObject( $source ) ) {
149 $oldpass = $row->user_password
;
150 $newpass = md5( "{$id}-{$oldpass}" );
152 $sql = "UPDATE user SET user_password='{$newpass}' " .
153 "WHERE user_id={$id}";
154 $wgDatabase->query( $sql, $fname );
158 function do_ipblocks_update() {
163 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_id" ) ) {
166 if ( !$wgDatabase->fieldExists( "ipblocks", "ipb_expiry" ) ) {
170 if ( $do1 ||
$do2 ) {
171 echo "Updating ipblocks table... ";
173 dbsource( "maintenance/archives/patch-ipblocks.sql", $wgDatabase );
176 dbsource( "maintenance/archives/patch-ipb_expiry.sql", $wgDatabase );
180 echo "...ipblocks is up to date.\n";
186 function do_interwiki_update() {
187 # Check that interwiki table exists; if it doesn't source it
189 if( $wgDatabase->tableExists( "interwiki" ) ) {
190 echo "...already have interwiki table\n";
193 echo "Creating interwiki table: ";
194 dbsource( "maintenance/archives/patch-interwiki.sql" );
196 echo "Adding default interwiki definitions: ";
197 dbsource( "maintenance/interwiki.sql" );
201 function do_index_update() {
202 # Check that proper indexes are in place
204 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
205 if( $meta->multiple_key
== 0 ) {
206 echo "Updating indexes to 20031107: ";
207 dbsource( "maintenance/archives/patch-indexes.sql" );
211 echo "...indexes seem up to 20031107 standards\n";
215 function do_linkscc_update() {
216 // Create linkscc if necessary
218 if( $wgDatabase->tableExists( "linkscc" ) ) {
219 echo "...have linkscc table.\n";
221 echo "Adding linkscc table... ";
222 dbsource( "maintenance/archives/patch-linkscc.sql", $wgDatabase );
227 function do_hitcounter_update() {
228 // Create hitcounter if necessary
230 if( $wgDatabase->tableExists( "hitcounter" ) ) {
231 echo "...have hitcounter table.\n";
233 echo "Adding hitcounter table... ";
234 dbsource( "maintenance/archives/patch-hitcounter.sql", $wgDatabase );
239 function do_recentchanges_update() {
241 if ( !$wgDatabase->fieldExists( "recentchanges", "rc_type" ) ) {
242 echo "Adding rc_type, rc_moved_to_ns, rc_moved_to_title...";
243 dbsource( "maintenance/archives/patch-rc_type.sql" , $wgDatabase );